<?php

namespace App\Http\Resources;


use Illuminate\Http\Resources\Json\JsonResource;

class AdConfigResource extends JsonResource
{
    public function toArray($request)
    {
        return collect($this->resource)->map(function ($item) {
            return [
                'adId' => data_get($item, 'id',0),
                'advId' => data_get($item, 'adv_id',''),
                'title' => data_get($item, 'title',''),
                'position' => data_get($item, 'position',''),
                'coverImage' => data_get($item, 'cover_image',''),
                'clickUrl' => data_get($item, 'click_url',''),
                'clickType' => data_get($item, 'click_type',1),
                'resourceUrl' => data_get($item, 'resource_url',''),
                'resourceType' => data_get($item, 'resource_type',1),
                'playDuration' => data_get($item, 'play_duration',0),
                'displayDuration' => data_get($item, 'display_duration',0),
                'isSkip' => (bool)data_get($item, 'is_skip',false),
                'skipUrl' => data_get($item, 'skip_url',''),
                'skipResourceUrl' => data_get($item, 'skip_url',''),
            ];
        })->toArray();
    }
}
